<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="爱心基金">
<style>
    .form-horizontal .controls {
        line-height: 40px;
        height: 40px;
    }

    .form-panel .time-input {
        width: 70px;
    }

    .query-button {
        margin-left: 5px;
    }

    .form-horizontal .money-label {
        width: 60px;
    }

    .money-span5 {
        width: 166px;
    }

    .money-p p {
        margin: 0 0 0 10px;
        padding: 0;
        height: 24px;
        line-height: 24px;
        font-size: 12px
    }

    .money-p div {
        float: left;
    }

    .money-p span {
        color: #6cb5f4;
    }

    .form-horizontal .rate-label {
        width: 120px;
    }

    .form-horizontal .time-label {
        width: 60px;
        line-height: 40px;
        margin-left: 20px;
    }

    .form-horizontal .money-label {
        width: 50px;
        line-height: 40px;
        margin-left: 5px;
    }

    .form-horizontal .money-controls {
        margin-left: 5px;
    }

    .money-span2 {
        width: 56px;
    }
</style>
<form id="searchForm" class="form-panel">
    <ul class="panel-content">
        <li>
            <div class="control-group span5">
                <div class="search-controls  controls">
                    <input type="text" name="offlineName" id="title" value="" placeholder="搜索关键字">
                </div>
            </div>
            <div class="form-actions span2">
                <button type="submit" class="query-button button  button-primary">
                    搜索
                </button>
            </div>
            <label class="time-label control-label">爱心捐款：</label>

            <div class="money-controls controls">
                <input type="text" class="time-input input-normal" name="sum" id="amountInput"
                       readonly="readonly"/>
            </div>

            <div class="money-span2   span2 control-group">
                <a class="button button-success" href="${basepath}/manage/fund/toOrganizeDetails ">
                    明细
                </a>
            </div>
            <label class="money-label control-label">已提现：</label>

            <div class="money-controls controls">
                <input type="text" class="time-input input-normal" name="cash" id="cashInput" readonly="readonly"/>
            </div>
            <label class="money-label control-label">未提现：</label>

            <div class="money-controls controls">
                <input type="text" class="time-input input-normal" name="unCash" id="unCashInput"
                       readonly="readonly"/>
            </div>
            <div class="money-span2  span2 control-group">
                <a class="button button-primary" href="javascript:add()">
                    提现
                </a>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>

<div id="addContent" style="display:none;">
    <form id="addForm" class="form-horizontal" action="${basepath}/manage/fund/insertJson" method="post">
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">可提现金额：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="unCash" id="unInput" disabled>元
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label"> <s>*</s>申请提现：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="money" data-messages="{regexp:'不是有效的数字'}"
                           data-rules="{regexp:/^\d+$/}" id="money">元
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label"> <s>*</s>收款人：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="payee" data-rules="{required:true}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label"><s>*</s>账号类型：</label>

                <div class="controls control-row4">
                    <select data-rules="{required:true}" name="accountType">
                        <option value="">-请选择-</option>
                        <option value="1">支付宝</option>
                        <option value="2">微信</option>
                        <option value="3">银行卡</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label"> <s>*</s>收款账号：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="payAccount" data-rule="{required:true}">
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    /*-------------------------------------------------------- 表格数据渲染start-----------------------------------*/
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '序号', dataIndex: 'id', elCls: 'center', width: '10%'},
                {title: '活动名称', dataIndex: 'offlineName', elCls: 'center', width: '30%'},
                {title: '捐款人', dataIndex: 'accountName', elCls: 'center', width: '30%'},
                {title: '捐款金额', dataIndex: 'contributions', elCls: 'center', width: '30%'}
            ];
    var store = new Store({
                url: '${basepath}/manage/offlineAccount/loadData',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: $("#phone").val(),
                    organizeID: sessionStorage.id
                },
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });

    /*-------------------------------------------------------- 表格数据渲染end-----------------------------------*/

    /*----------------------------------------------新增提现表单处理 begin------------------------------------*/
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addDialog.close();
        }
    }).render();
    var addDialog = new BUI.Overlay.Dialog({
        title: '提现申请',
        width: 500,
        height: 340,
        contentId: 'addContent',
        success: function () {
            if (addForm.isValid()) {
                addForm.ajaxSubmit();
                window.location.href = "${basepath}/manage/fund/toOrganizeList"
            } else {
                addForm.valid();
            }
        }
    });
    //添加按钮事件
    function add() {
        addDialog.show();
    }
    /*----------------------------------------------新增提现表单处理 end------------------------------------*/
    //查询的是爱心捐款input、已提现、未提现的值
    function queryInput() {
        $.ajax({
            type: "GET",
            url: "${basepath}/manage/organize/selectOrganizeFund",
            dataType: "json",
            success: function (data) {
                var uneCash = 0;
                var cash = 0;
                var sum = 0;
                var inputList = data.data;
                //不要取到null值或者没有空值就执行这个语句
                if (inputList.unCash != null &&inputList.unCash != "") {
                    uneCash = uneCash + parseInt(inputList.unCash);
                }
                if (inputList.cash != null && inputList.cash != "") {
                    cash = cash + parseInt(inputList.cash);
                }
                if (inputList.sum != null && inputList.sum != "") {
                    sum = sum + parseInt(inputList.sum);
                }

                $("#unCashInput").val(uneCash);
                $("#cashInput").val(cash);
                $("#amountInput").val(sum);
                //给弹出框塞可提现金额值
                $("#unInput").val(uneCash);
            }

        })
    }
    queryInput();
</script>

</@page.pageBase>